package blazingbubble.network.game.strategy;

import moltencore.network.protocol.*;
import spark.network.protocol.Response;
import spark.network.strategy.IProtocolHandleStrategy;
import spark.network.protocol.Base;
import spark.network.protocol.Acknowledgement;
import org.apache.log4j.Logger;
import spark.utility.OutWrapper;

import java.util.LinkedList;
import java.util.Collection;

public class GameStartedStrategy implements IProtocolHandleStrategy<GameStarted> {
	private Logger logger = Logger.getLogger(GameStartedStrategy.class);

	private LinkedList<IStartGameListener> startGameListeners = new LinkedList<IStartGameListener>();

	public void addStartGameListener(IStartGameListener startGameListener) {
		startGameListeners.add(startGameListener);
	}

	@Override
	public void handle(GameStarted packet, OutWrapper<Response> acknowledgement, Collection<Base> additionalData) {
		notifyListenersStartGame();
		acknowledgement.value = new Acknowledgement(packet);
	}

	private void notifyListenersStartGame() {
		for(IStartGameListener startGameListener : startGameListeners) {
			startGameListener.gameStarted();
		}
	}
}